from header_common import *
from header_operations import *
from header_mission_templates import *
from header_animations import *
from module_constants import *

####################################################################################################################
#   Each mission-template is a tuple that contains the following fields:
#  1) Mission-template id (string): used for referencing mission-templates in other files.
#     The prefix mt_ is automatically added before each mission-template id
#
#  2) Mission-template flags (int): See header_mission-templates.py for a list of available flags
#  3) Mission-type(int): Which mission types this mission template matches.
#     For mission-types to be used with the default party-meeting system,
#     this should be 'charge' or 'charge_with_ally' otherwise must be -1.
#     
#  4) Mission description text (string).
#  5) List of spawn records (list): Each spawn record is a tuple that contains the following fields:
#    5.1) entry-no: Troops spawned from this spawn record will use this entry
#    5.2) spawn flags. 
#    5.3) alter flags. which equipment will be overriden
#    5.4) ai flags.
#    5.5) Number of troops to spawn.
#    5.6) list of equipment to add to troops spawned from here (maximum 8).
#  6) List of triggers (list).
#     See module_triggers.py for infomation about triggers.
#
#  Please note that mission templates is work in progress and can be changed in the future versions.
# 
####################################################################################################################

pilgrim_disguise = [itm_pilgrim_hood,itm_pilgrim_disguise,itm_practice_staff, itm_throwing_daggers]

mission_templates = [
  (
    "town_default",0,-1,
    "Default town visit",
    [(0,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),
     (1,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(2,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(3,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(4,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(5,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(6,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(7,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),
     (8,mtef_scene_source,af_override_horse,0,1,[]),(9,mtef_scene_source,af_override_horse,0,1,[]),(10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_visitor_source,af_override_horse,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),(19,mtef_visitor_source,af_override_horse,0,1,[]),(20,mtef_visitor_source,af_override_horse,0,1,[]),(21,mtef_visitor_source,af_override_horse,0,1,[]),(22,mtef_visitor_source,af_override_horse,0,1,[]),(23,mtef_visitor_source,af_override_horse,0,1,[]),(24,mtef_visitor_source,af_override_horse,0,1,[]),
     (25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,0,1,[]),(28,mtef_visitor_source,af_override_horse,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[])
     ],
    [
      (1, 0, ti_once, [], [
          (store_current_scene, reg(1)),
          (scene_set_slot, reg(1), slot_scene_visited, 1),
        ]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
    ],
  ),
# This template is used in party encounters and such.
# 
  (
    "conversation_encounter",0,-1,
    "Conversation_encounter",
    [( 0,mtef_visitor_source,0,group(1),1,[]),( 1,mtef_visitor_source,0,0,1,[]),
     ( 2,mtef_visitor_source,0,group(1),1,[]),( 3,mtef_visitor_source,0,group(1),1,[]),( 4,mtef_visitor_source,0,group(1),1,[]),( 5,mtef_visitor_source,0,group(1),1,[]),( 6,mtef_visitor_source,0,group(1),1,[]),
     ( 7,mtef_visitor_source,0,group(1),1,[]),( 8,mtef_visitor_source,0,group(1),1,[]),( 9,mtef_visitor_source,0,group(1),1,[]),(10,mtef_visitor_source,0,group(1),1,[]),(11,mtef_visitor_source,0,group(1),1,[]),
    #prisoners now...
     (12,mtef_visitor_source,0,group(1),1,[]),(13,mtef_visitor_source,0,group(1),1,[]),(14,mtef_visitor_source,0,group(1),1,[]),(15,mtef_visitor_source,0,group(1),1,[]),(16,mtef_visitor_source,0,group(1),1,[]),
    #Other party
     (17,mtef_visitor_source,0,group(1),1,[]),(18,mtef_visitor_source,0,group(1),1,[]),(19,mtef_visitor_source,0,group(1),1,[]),(20,mtef_visitor_source,0,group(1),1,[]),(21,mtef_visitor_source,0,group(1),1,[]),
     (22,mtef_visitor_source,0,group(1),1,[]),(23,mtef_visitor_source,0,group(1),1,[]),(24,mtef_visitor_source,0,group(1),1,[]),(25,mtef_visitor_source,0,group(1),1,[]),(26,mtef_visitor_source,0,group(1),1,[]),
     (27,mtef_visitor_source,0,group(1),1,[]),(28,mtef_visitor_source,0,group(1),1,[]),(29,mtef_visitor_source,0,group(1),1,[]),(30,mtef_visitor_source,0,group(1),1,[]),(31,mtef_visitor_source,0,group(1),1,[]),
     ],
    [],
  ),
  
#----------------------------------------------------------------
#mission templates before this point are hardwired into the game.
#-----------------------------------------------------------------
  (
    "town_disguised",0,-1,
    "Default town visit",
    [(0,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (1,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (2,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (3,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (4,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (5,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (6,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     (7,mtef_scene_source,af_override_all,group(1),1,pilgrim_disguise),
     
     (8,mtef_scene_source,af_override_horse,0,1,[]),
     (9,mtef_scene_source,af_override_horse,0,1,[]),(10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_scene_source,af_override_horse,0,1,[]),(18,mtef_scene_source,af_override_horse,0,1,[]),(19,mtef_scene_source,af_override_horse,0,1,[]),(20,mtef_scene_source,af_override_horse,0,1,[]),(21,mtef_scene_source,af_override_horse,0,1,[]),(22,mtef_scene_source,af_override_horse,0,1,[]),(23,mtef_scene_source,af_override_horse,0,1,[]),(24,mtef_scene_source,af_override_horse,0,1,[]),
     (25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,0,1,[]),(28,mtef_visitor_source,af_override_horse,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[])
     ],
    [
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_disguised")], []),
    ],
  ),
  (
    "visit_town_horseback",0,-1,
    "You enter the area",
    [(0,mtef_scene_source|mtef_team_1,0,0,1,[]),
     (1,mtef_scene_source|mtef_team_1,0,0,1,[]),(2,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(3,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(4,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(5,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(6,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(7,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),
     (8,mtef_scene_source,af_override_horse,0,1,[]),
     (9,mtef_scene_source,af_override_horse,0,1,[]),(10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_scene_source,af_override_horse,0,1,[]),(18,mtef_scene_source,af_override_horse,0,1,[]),(19,mtef_scene_source,af_override_horse,0,1,[]),(20,mtef_scene_source,af_override_horse,0,1,[]),(21,mtef_scene_source,af_override_horse,0,1,[]),(22,mtef_scene_source,af_override_horse,0,1,[]),(23,mtef_scene_source,af_override_horse,0,1,[]),(24,mtef_scene_source,af_override_horse,0,1,[]),
     (25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,0,1,[]),(28,mtef_visitor_source,af_override_horse,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[])
     ],
    [
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
     ],
  ),
  (
    "zendar_novice_master_talk",0,-1,
    "Default town visit",
    [(0,mtef_scene_source,af_override_horse,group(1),1,[]),
     (1,mtef_scene_source,af_override_horse,0,1,[]),(2,mtef_scene_source,af_override_horse,0,1,[]),(3,mtef_scene_source,af_override_horse,0,1,[]),(4,mtef_scene_source,af_override_horse,0,1,[]),(5,mtef_scene_source,af_override_horse,0,1,[]),(6,mtef_scene_source,af_override_horse,0,1,[]),(7,mtef_scene_source,af_override_horse,0,1,[]),(8,mtef_scene_source,af_override_horse,0,1,[]),
     (9,mtef_scene_source,af_override_horse,0,1,[]),(10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,af_override_horse,0,1,[]),(14,mtef_scene_source,af_override_horse,0,1,[]),(15,mtef_scene_source,af_override_horse,0,1,[]),(16,mtef_scene_source,af_override_horse,0,1,[])],
    [
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_val(0), ti_val(1), ti_once, [], [(start_mission_conversation,"trp_trainer")]),
    ],
  ),
  
  (
    "visit_town_castle",0,-1,
    "You enter the halls of the lord.",
    [(0,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),
     (1,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(2,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(3,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(4,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(5,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(6,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),(7,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),
     (8,mtef_scene_source,af_override_horse,0,1,[]), (9,mtef_scene_source,af_override_horse,0,1,[]), (10,mtef_scene_source,af_override_horse,0,1,[]),(11,mtef_scene_source,af_override_horse,0,1,[]),(12,mtef_scene_source,af_override_horse,0,1,[]),(13,mtef_scene_source,af_override_horse,0,1,[]),(14,mtef_scene_source,af_override_horse,0,1,[]),(15,mtef_scene_source,af_override_horse,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_scene_source,af_override_horse,0,1,[]),(18,mtef_scene_source,af_override_horse,0,1,[]),(19,mtef_scene_source,af_override_horse,0,1,[]),(20,mtef_scene_source,af_override_horse,0,1,[]),(21,mtef_scene_source,af_override_horse,0,1,[]),(22,mtef_scene_source,af_override_horse,0,1,[]),(23,mtef_scene_source,af_override_horse,0,1,[]),(24,mtef_scene_source,af_override_horse,0,1,[]),
     (25,mtef_scene_source,af_override_horse,0,1,[]),(26,mtef_scene_source,af_override_horse,0,1,[]),(27,mtef_scene_source,af_override_horse,0,1,[]),(28,mtef_scene_source,af_override_horse,0,1,[]),(29,mtef_scene_source,af_override_horse,0,1,[]),(30,mtef_scene_source,af_override_horse,0,1,[]),(31,mtef_scene_source,af_override_horse,0,1,[])
     ],
    [
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
    ],
  ),
  
  (
    "visit_town_arena",0,-1,
    "You enter the arena",
    [(0,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),
     (50,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),(51,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),
     (52,mtef_scene_source,af_override_horse,0,1,[]),(53,mtef_scene_source,af_override_horse,0,1,[]),(54,mtef_scene_source,af_override_horse,0,1,[]),(55,mtef_scene_source,af_override_horse,0,1,[]),(56,mtef_scene_source,af_override_horse,0,1,[]),
     (57,mtef_scene_source,af_override_horse,0,1,[]),(58,mtef_scene_source,af_override_horse,0,1,[]),(59,mtef_scene_source,af_override_horse,0,1,[]),(60,mtef_scene_source,af_override_horse,0,1,[]),(61,mtef_scene_source,af_override_horse,0,1,[]),(62,mtef_scene_source,af_override_horse,0,1,[]),(63,mtef_scene_source,af_override_horse,0,1,[])
     ],
    [
      (1, 0, ti_once, [], [
          (store_current_scene, reg(1)),
          (scene_set_slot, reg(1), slot_scene_visited, 1),
        ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
    ],
  ),
  (
    "visit_town_arena_disguised",0,-1,
    "You enter the arena",
    [(0,mtef_scene_source|mtef_team_1,af_override_horse,group(1),1,[]),
     (50,mtef_scene_source|mtef_team_1,af_override_all,group(1),1,pilgrim_disguise),(51,mtef_scene_source|mtef_team_1,af_override_horse,0,1,[]),
     (52,mtef_scene_source,af_override_horse,0,1,[]),(53,mtef_scene_source,af_override_horse,0,1,[]),(54,mtef_scene_source,af_override_horse,0,1,[]),(55,mtef_scene_source,af_override_horse,0,1,[]),(56,mtef_scene_source,af_override_horse,0,1,[]),
     (57,mtef_scene_source,af_override_horse,0,1,[]),(58,mtef_scene_source,af_override_horse,0,1,[]),(59,mtef_scene_source,af_override_horse,0,1,[]),(60,mtef_scene_source,af_override_horse,0,1,[]),(61,mtef_scene_source,af_override_horse,0,1,[]),(62,mtef_scene_source,af_override_horse,0,1,[]),(63,mtef_scene_source,af_override_horse,0,1,[])
     ],
    [
      (1, 0, ti_once, [], [
          (store_current_scene, reg(1)),
          (scene_set_slot, reg(1), slot_scene_visited, 1),
        ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_disguised")], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
    ],
  ),

  (
    "lead_charge",mtf_battle_mode,charge,
    "You lead your men to battle.",
    [
     (1,mtef_defenders,0,group(1)|aif_start_alarmed,8,[]),
     (0,mtef_defenders,0,group(1)|aif_start_alarmed,0,[]),
     (4,mtef_attackers,0,aif_start_alarmed,8,[]),
     (4,mtef_attackers,0,aif_start_alarmed,0,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$defender_reinforcement_stage",0),(assign,"$attacker_reinforcement_stage",0)]),
      (1, 0, 5, [(lt,"$defender_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_defender_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,0,4),(val_add,"$defender_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_attacker_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,3,4),(val_add,"$attacker_reinforcement_stage",1)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),
                        (ge,reg(1),10),(all_enemies_defeated,2),
                        (neg|main_hero_fallen,0),
                        (set_mission_result,1),
                        (assign, "$g_battle_result", 1),
                        (display_message,"str_msg_battle_won"),
                        (assign,"$battle_won",1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),(finish_mission,1)]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_use_baggage_for_inventory")], []),
    ],
  ),
  (
    "charge_with_allies",mtf_battle_mode,charge_with_ally,
    "Taking a handful of fighters with you, you set off to patrol the area.",
    [
     (1,mtef_defenders,0,group(1)|aif_start_alarmed,8,[]),
     (0,mtef_defenders,0,group(1)|aif_start_alarmed,0,[]),
     (4,mtef_attackers,0,aif_start_alarmed,8,[]),
     (4,mtef_attackers,0,aif_start_alarmed,0,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$defender_reinforcement_stage",0),(assign,"$attacker_reinforcement_stage",0)]),
      (1, 0, 5, [(lt,"$defender_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_defender_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,0,4),(val_add,"$defender_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_attacker_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,3,4),(val_add,"$attacker_reinforcement_stage",1)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),
                        (ge,reg(1),10),(all_enemies_defeated,2),
                        (neg|main_hero_fallen,0),
                        (set_mission_result,1),
                        (assign, "$g_battle_result", 1),
                        (display_message,"str_msg_battle_won"),
                        (assign,"$battle_won",1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),(finish_mission,1)]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_use_baggage_for_inventory")], []),
    ],
  ),

  (
    "charge_with_allies_old",mtf_battle_mode,charge_with_ally,
    "Taking a handful of fighters with you, you set off to patrol the area.",
    [(1,mtef_leader_only,0,group(1),1,[]),
     (1,mtef_no_leader,0,group(1)|aif_start_alarmed,2,[]),
     (1,mtef_reverse_order|mtef_ally_party,0,group(1)|aif_start_alarmed,3,[]),
     (0,mtef_no_leader,0,group(1)|aif_start_alarmed,0,[]),
     (0,mtef_reverse_order|mtef_ally_party,0,group(1)|aif_start_alarmed,0,[]),
     (3,mtef_reverse_order|mtef_enemy_party,0,aif_start_alarmed,6,[]),
     (4,mtef_reverse_order|mtef_enemy_party,0,aif_start_alarmed,0,[])],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$enemy_reinforcement_stage",0),(assign,"$friend_reinforcement_stage",0),(assign,"$ally_reinforcement_stage",0)]),
      
      (1, 0, 5, [(lt,"$enemy_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_enemy_count,reg(2)),(lt,reg(2),3)],
       [(add_reinforcements_to_entry,6,3),(val_add,"$enemy_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$friend_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_friend_count,reg(2)),(lt,reg(2),2)],
       [(add_reinforcements_to_entry,3,1),(val_add,"$friend_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$ally_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_ally_count,reg(2)),  (lt,reg(2),2)],
       [(add_reinforcements_to_entry,4,2),(val_add,"$ally_reinforcement_stage",1)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),
                        (ge,reg(1),10),
                        (all_enemies_defeated,2),
                        (neg|main_hero_fallen,0),
                        (set_mission_result,1),
                        (assign, "$g_battle_result", 1),
                        (display_message,"str_msg_battle_won"),
                        (assign,"$battle_won",1),
                        ],
       [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen,0)],
       [(set_mission_result,-1),(finish_mission,1)]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_use_baggage_for_inventory")], []),
    ],
  ),
  (
    "lead_charge_old",mtf_battle_mode,charge,
    "You lead your men to battle.",
    [
     (1,mtef_leader_only,0,group(1),1,[]),
     (1,mtef_no_leader,0,group(1)|aif_start_alarmed,5,[]),
     (0,mtef_no_leader,0,group(1)|aif_start_alarmed,0,[]),
     (3,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,6,[]),
     (4,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,0,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$enemy_reinforcement_stage",0),(assign,"$friend_reinforcement_stage",0)]),
      (1, 0, 5, [(lt,"$enemy_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_enemy_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,4,3),(val_add,"$enemy_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$friend_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_friend_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,2,3),(val_add,"$friend_reinforcement_stage",1)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),
                        (ge,reg(1),10),(all_enemies_defeated,2),
                        (neg|main_hero_fallen,0),
                        (set_mission_result,1),
                        (assign, "$g_battle_result", 1),
                        (display_message,"str_msg_battle_won"),
                        (assign,"$battle_won",1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),(finish_mission,1)]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_use_baggage_for_inventory")], []),
    ],
  ),

  (
    "castle_attack_walls",mtf_battle_mode,-1,
    "You attack the walls of the castle...",
    [
     (0,mtef_attackers,af_override_horse,aif_start_alarmed,1,[]),
     (0,mtef_attackers,af_override_horse,aif_start_alarmed,4,[]),
     (10,mtef_defenders,af_override_horse,aif_start_alarmed,2,[]),
     (11,mtef_defenders,af_override_horse,aif_start_alarmed,2,[]),
     (12,mtef_defenders,af_override_horse,aif_start_alarmed,2,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),
        
      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$enemy_reinforcement_stage",0),(assign,"$friend_reinforcement_stage",0)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),(ge,reg(1),10),(all_enemies_defeated,2),(neg|main_hero_fallen,0),(set_mission_result,1),(display_message,"str_msg_battle_won"),(assign,"$battle_won",1),(assign, "$g_battle_result", 1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen,0)],
          [(set_mission_result,-1),(finish_mission,1)]),
       #Lead attackers climb the ramps over to the walls
      # We assume:
      # entry_point 1 = start of first ramp
      # entry_point 2 = end of first ramp
      # entry_point 3 = start of second ramp
      # entry_point 4 = end of second ramp
      
      (3, 0, 0, [], 
       [
           (get_player_agent_no, reg(20)),
           (entry_point_get_position,1,1),
           (entry_point_get_position,2,2),
           (entry_point_get_position,3,3),
           (entry_point_get_position,4,4),
           (try_for_agents,reg(5)),
             (neq, reg(5), reg(20)),
             (agent_is_alive, reg(5)),
             (agent_is_human, reg(5)),
             (neg|agent_is_defender, reg(5)),
             (agent_get_slot, reg(6), reg(5), 1),
             (str_store_agent_name,40,reg(5)),
             (assign,reg(40),reg(6)),
#             (display_message, "str_debug_string_1"),
             (agent_get_position, 5, reg(5)),
             (try_begin),
               (eq, reg(6), 0),
               (this_or_next|position_is_behind_position, 5, 2), 
               (position_is_behind_position, 5, 4),
               (get_distance_between_positions, reg(7), 5, 1),
               (get_distance_between_positions, reg(8), 5, 3),
               (try_begin),
                 (lt, reg(7), reg(8)), #agent is closer to entry point 1
                 (get_distance_between_positions, reg(10), 5, 2),
                 (ge,reg(10),110),
                 (agent_set_scripted_destination, reg(5), 1),
                 (agent_set_slot,reg(5),1,1),
               (else_try),          #agent is closer to entry point 3
                 (get_distance_between_positions, reg(10), 5, 4),
                 (ge,reg(10),110),
                 (agent_set_scripted_destination,reg(5), 3),
                 (agent_set_slot,reg(5),1,3),
               (try_end),
             (else_try),
               (get_distance_between_positions,reg(9),5,reg(6)),
               (lt, reg(9), 110),
               (try_begin),
                 (eq,reg(6),1),
                 (agent_set_scripted_destination, reg(5), 2),
                 (agent_set_slot,reg(5),1,2),
               (else_try),
                 (eq,reg(6),3),
                 (agent_set_scripted_destination, reg(5), 4),
                 (agent_set_slot,reg(5),1,4),
               (else_try),
                 (eq,reg(6),2),
                 (neg|position_is_behind_position, 5, 2), 
                 (agent_set_slot,reg(5),1,0),
                 (agent_clear_scripted_mode,reg(5)),
               (else_try),
                 (eq,reg(6),4),
                 (neg|position_is_behind_position, 5, 4), 
                 (agent_set_slot,reg(5),1,0),
                 (agent_clear_scripted_mode,reg(5)),
               (try_end),
             (try_end),
           (try_end),
        ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_use_baggage_for_inventory")], []),
    ],
  ),

  (
    "castle_visit",0,-1,
    "Castle visit",
    [(0,mtef_scene_source|mtef_team_2,0,group(1),1,[]),
     (1,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(2,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(3,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(4,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(5,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(6,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),(7,mtef_scene_source|mtef_team_2,af_override_horse,0,1,[]),
     (8,mtef_scene_source,af_override_horse,0,1,[]),(9,mtef_scene_source,af_override_horse,0,1,[]),
     # Party members
     (10,mtef_enemy_party|mtef_reverse_order,af_override_horse,aif_start_alarmed,1,[]),
     (11,mtef_enemy_party|mtef_reverse_order,af_override_horse,aif_start_alarmed,1,[]),
     (12,mtef_enemy_party|mtef_reverse_order,af_override_horse,aif_start_alarmed,2,[]),
     (13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),(16,mtef_scene_source,0,0,1,[]),
     (17,mtef_scene_source,af_override_horse,0,1,[]),(18,mtef_scene_source,af_override_horse,0,1,[]),(19,mtef_scene_source,af_override_horse,0,1,[]),(20,mtef_scene_source,af_override_horse,0,1,[]),(21,mtef_scene_source,af_override_horse,0,1,[]),(22,mtef_scene_source,af_override_horse,0,1,[]),(23,mtef_scene_source,af_override_horse,0,1,[]),(24,mtef_scene_source,af_override_horse,0,1,[]),
     (25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,0,1,[]),(28,mtef_visitor_source,af_override_horse,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[])
     ],
    [
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),

      (ti_before_mission_start, 0, 0, [],
          [(scene_prop_disable,"spr_ramp_12m"),(scene_prop_disable,"spr_portcullis")]),
    ],
  ),

#note : we should not be setting groups for teams. This is done automatically.  
  (
    "zendar_training_fight",mtf_arena_fight,-1,
    "You will fight a match in the arena.",
    [
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_shield,itm_practice_sword]),
      (1,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_staff]),
      (2,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_staff]),
      (3,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword]),
#      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[]),
#      (1,mtef_visitor_source|mtef_team_2,af_override_all        ,aif_start_alarmed,1,[]),
#      (2,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[]),
#      (3,mtef_visitor_source|mtef_team_4,af_override_all      ,aif_start_alarmed,1,[]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_give_up_fight")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(jump_to_scene,"scn_zendar_center"),]),
      (1, 3, ti_once, [(main_hero_fallen,0)],
       [(jump_to_scene,"scn_zendar_center")]),
      (1, 3, ti_once, [(store_mission_timer_a,reg(1)),(ge,reg(1),1),(num_active_teams_le,1),(neg|main_hero_fallen,0),(assign,"$training_fight_won",1)],
       [(jump_to_scene,"scn_zendar_center")]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
    ],
  ),
  (
    "zendar_arena_fight",mtf_arena_fight,-1,
    "You will fight a match in the arena. The fighter to score 9 points first wins.",
    [
      (16,mtef_visitor_source,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (1,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (2,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (3,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (4,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (5,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_red_tourney_armor]),
      (6,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_red_tourney_armor]),
      (7,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (9,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (10,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (11,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (12,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_blue_tourney_armor]),
      (13,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (14,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_blue_tourney_armor]),
      (15,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_give_up_fight")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(jump_to_scene,"scn_zendar_center"),]),

      (1, 4, ti_once, [(main_hero_fallen,0)],
       [(jump_to_scene,"scn_zendar_center")]),
      (1, 4, ti_once, [(num_active_teams_le,1),(neg|main_hero_fallen,0)],
       [(store_remaining_team_no,"$zendar_winner_team"),(assign,"$arena_fight_won",1),(jump_to_scene,"scn_zendar_center")]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
    ],
  ),
  (
    "sneak_caught_fight",mtf_arena_fight,-1,
    "You must fight your way out!",
    [
      (0,mtef_visitor_source|mtef_team_1,af_override_all|af_equip_wooden_staff,aif_start_alarmed,1,pilgrim_disguise),
      (25,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (32,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
#      (9,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_do_you_wish_to_surrender")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(jump_to_menu,"mnu_captivity_start_castle_defeat"),(finish_mission,0),]),
      
      (1, 0, ti_once, [], [(play_sound,"snd_sneak_town_halt")]),
      (0, 3, 0,
       [
           (main_hero_fallen,0),
        ],
       [(jump_to_menu,"mnu_captivity_start_castle_defeat"),(finish_mission,0)]),
      (5, 1, ti_once, [(num_active_teams_le,1),(neg|main_hero_fallen)],
       [(assign,"$auto_menu",-1),(jump_to_menu,"mnu_sneak_into_town_caught_ran_away"),(finish_mission,1)]),
      (ti_on_leave_area, 0, ti_once, [],
       [(assign,"$auto_menu",-1),(jump_to_menu,"mnu_sneak_into_town_caught_ran_away"),(finish_mission,0)]),

      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
      
    ],
  ),
  (
    "betrayed_by_lord",mtf_battle_mode,-1,
    "You must fight your way out!",
    [
      (0,mtef_visitor_source|mtef_team_1,af_override_all|af_equip_wooden_staff,aif_start_alarmed,1,[itm_practice_staff]),
      (1,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (8,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_do_you_wish_to_surrender")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(jump_to_scene,"scn_zendar_center"),]),
        
      (1, 3, ti_once, [(main_hero_fallen,0)],
       [(jump_to_scene,"scn_zendar_center")]),
      (1, 3, ti_once, [(num_active_teams_le,1),(neg|main_hero_fallen,0)],
       [(finish_mission,1)]),
    ],
  ),

   (
    "ai_training",mtf_battle_mode,-1,
    "You start training.",
    [
     (1,mtef_leader_only,0,group(1),1,[]),
     (1,mtef_no_leader,0,group(1)|aif_start_alarmed,5,[]),
     (0,mtef_no_leader,0,group(1)|aif_start_alarmed,0,[]),
#     (3,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,6,[]),
#     (4,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,0,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_give_up_fight")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),
    ],
  ),

  (
    "arena_melee_fight",mtf_arena_fight,-1,
    "You enter a melee fight in the arena.",
    [
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (1,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (2,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (3,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (4,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (5,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_red_tourney_armor]),
      (6,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_red_tourney_armor]),
      (7,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_red_tourney_armor, itm_red_tourney_helmet]),

      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (9,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (10,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (11,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (12,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_blue_tourney_armor]),
      (13,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (14,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_blue_tourney_armor]),
      (15,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor]),

      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_green_tourney_armor, itm_green_tourney_helmet]),
      (17,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_green_tourney_armor, itm_green_tourney_helmet]),
      (18,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_green_tourney_armor, itm_green_tourney_helmet]),
      (19,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_green_tourney_armor, itm_green_tourney_helmet]),
      (20,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_green_tourney_armor, itm_green_tourney_helmet]),
      (21,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (22,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_green_tourney_armor]),
      (23,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_green_tourney_armor, itm_green_tourney_helmet]),

      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_practice_horse,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (25,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (26,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (27,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (28,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_bow,itm_practice_arrows,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (29,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_gold_tourney_armor]),
      (30,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_practice_horse,itm_gold_tourney_armor]),
      (31,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_practice_shield,itm_practice_horse,itm_gold_tourney_armor, itm_gold_tourney_helmet]),

      (51,mtef_visitor_source,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_give_up_fight")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

        
      (1, 4, ti_once, [(this_or_next|main_hero_fallen),(num_active_teams_le,1)],
       [
           (try_begin),
             (num_active_teams_le,1),
             (neg|main_hero_fallen),
             (assign,"$arena_fight_won",1),
           (try_end),
           (store_remaining_team_no,"$arena_winner_team"),
           (try_begin),
             (eq, "$sneaked_into_town",1),
             (assign,reg(10),"mt_visit_town_arena_disguised"),
           (else_try),
             (assign,reg(10),"mt_visit_town_arena"),
           (try_end),
           (set_jump_mission,reg(10)),
           (party_get_slot, reg(11), "$current_town", slot_town_arena),
           (set_jump_entry, 50),
           (jump_to_scene,reg(11)),
           ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
    ],
  ),

  (
    "arena_melee_fight_no_ranged",mtf_arena_fight,-1,
    "You enter a melee fight in the arena.",
    [
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),
      (0,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_red_tourney_armor, itm_red_tourney_helmet]),

      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),
      (8,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_blue_tourney_armor,itm_blue_tourney_helmet]),

      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),
      (16,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_green_tourney_armor]),

      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_heavy_practice_sword,itm_gold_tourney_armor, itm_gold_tourney_helmet]),

      (51,mtef_visitor_source,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
    ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_give_up_fight")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

        
      (1, 4, ti_once, [(this_or_next|main_hero_fallen),(num_active_teams_le,1)],
       [
           (try_begin),
             (num_active_teams_le,1),
             (neg|main_hero_fallen),
             (assign,"$arena_fight_won",1),
           (try_end),
           (store_remaining_team_no,"$arena_winner_team"),
           (try_begin),
             (eq, "$sneaked_into_town",1),
             (assign,reg(10),"mt_visit_town_arena_disguised"),
           (else_try),
             (assign,reg(10),"mt_visit_town_arena"),
           (try_end),
           (set_jump_mission,reg(10)),
           (party_get_slot, reg(11), "$current_town", slot_town_arena),
           (set_jump_entry, 50),
           (jump_to_scene,reg(11)),
           ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
    ],
  ),

   (
    "tutorial",0,-1,
    "You enter the training ground.",
    [
        (1,mtef_leader_only,af_override_horse,0,1,[]), #af_override_weapons
        (2,mtef_scene_source,af_override_horse,0,1,[]), #af_override_weapons
        (2,mtef_scene_source,af_override_horse,0,1,[]), #af_override_weapons
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [(question_box,"str_do_you_wish_to_leave_tutorial")]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),
        (eq,":answer",0),
        (finish_mission,0),
        (leave_encounter),
        (change_screen_return),
        (troop_remove_item, "trp_player", "itm_tutorial_sword"),
        (troop_remove_item, "trp_player", "itm_tutorial_axe"),
        (troop_remove_item, "trp_player", "itm_tutorial_spear"),
        (troop_remove_item, "trp_player", "itm_tutorial_club"),
        (troop_remove_item, "trp_player", "itm_tutorial_battle_axe"),
        (troop_remove_item, "trp_player", "itm_tutorial_arrows"),
        (troop_remove_item, "trp_player", "itm_tutorial_bolts"),
        (troop_remove_item, "trp_player", "itm_tutorial_short_bow"),
        (troop_remove_item, "trp_player", "itm_tutorial_crossbow"),
        (troop_remove_item, "trp_player", "itm_tutorial_throwing_daggers"),
        
        (check_quest_active, "qst_destroy_dummies"),
        (cancel_quest,"qst_destroy_dummies"),
        ]),
#      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_tutorial")], []),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),

        
      (0, 0, ti_once, [],
       [
        (assign, "$tutorial_enter_melee", 0),
        (assign, "$tutorial_enter_ranged", 0),
        (assign, "$tutorial_enter_mounted", 0),
        (assign, "$tutorial_camp_stage", 0),
        (assign, "$tutorial_quest_taken", 0),
        (assign, "$tutorial_quest_succeeded", 0),
        (assign, "$tutorial_num_total_dummies_destroyed", 0),
           
        (entry_point_get_position,2,2),#Trainer
        (entry_point_get_position,16,16),#Horse
        (set_spawn_position, 16),
        (spawn_horse, "itm_tutorial_saddle_horse"),

        (troop_remove_item, "trp_tutorial_chest_1", "itm_tutorial_sword"),
        (troop_remove_item, "trp_tutorial_chest_1", "itm_tutorial_axe"),
        (troop_remove_item, "trp_tutorial_chest_1", "itm_tutorial_spear"),
        (troop_remove_item, "trp_tutorial_chest_1", "itm_tutorial_club"),
        (troop_remove_item, "trp_tutorial_chest_1", "itm_tutorial_battle_axe"),
        (troop_remove_item, "trp_tutorial_chest_2", "itm_tutorial_arrows"),
        (troop_remove_item, "trp_tutorial_chest_2", "itm_tutorial_bolts"),
        (troop_remove_item, "trp_tutorial_chest_2", "itm_tutorial_short_bow"),
        (troop_remove_item, "trp_tutorial_chest_2", "itm_tutorial_crossbow"),
        (troop_remove_item, "trp_tutorial_chest_2", "itm_tutorial_throwing_daggers"),
        (troop_add_item, "trp_tutorial_chest_1", "itm_tutorial_sword"),
        (troop_add_item, "trp_tutorial_chest_1", "itm_tutorial_axe"),
        (troop_add_item, "trp_tutorial_chest_1", "itm_tutorial_spear"),
        (troop_add_item, "trp_tutorial_chest_1", "itm_tutorial_club"),
        (troop_add_item, "trp_tutorial_chest_1", "itm_tutorial_battle_axe"),
        (troop_add_item, "trp_tutorial_chest_2", "itm_tutorial_arrows"),
        (troop_add_item, "trp_tutorial_chest_2", "itm_tutorial_bolts"),
        (troop_add_item, "trp_tutorial_chest_2", "itm_tutorial_short_bow"),
        (troop_add_item, "trp_tutorial_chest_2", "itm_tutorial_crossbow"),
        (troop_add_item, "trp_tutorial_chest_2", "itm_tutorial_throwing_daggers"),
        ]
       ),
     
      (1, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (get_player_agent_no, ":player_agent"),
                       (ge, ":player_agent", 0),
                       (agent_get_position, 1, ":player_agent"),
                       (entry_point_get_position,3,3),
                       (get_distance_between_positions, ":distance_to_area", 1, 3),
                       (lt, ":distance_to_area", 500),
                       (eq, "$tutorial_enter_melee", 0),],
       [(tutorial_box,"str_tutorial_enter_melee", "str_tutorial"), (val_add,"$tutorial_enter_melee", 1)]),
      (1, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (get_player_agent_no, ":player_agent"),
                       (ge, ":player_agent", 0),
                       (neg|conversation_screen_is_active),
                       (agent_get_position, 1, ":player_agent"),
                       (entry_point_get_position,4,4),
                       (get_distance_between_positions, ":distance_to_area", 1, 4),
                       (lt, ":distance_to_area", 500),
                       (eq, "$tutorial_enter_ranged", 0),],
       [(tutorial_box,"str_tutorial_enter_ranged", "str_tutorial"), (val_add,"$tutorial_enter_ranged", 1)]),
      (1, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (get_player_agent_no, ":player_agent"),
                       (ge, ":player_agent", 0),
                       (neg|conversation_screen_is_active),
                       (agent_get_position, 1, ":player_agent"),
                       (entry_point_get_position,5,5),
                       (get_distance_between_positions, ":distance_to_area", 1, 5),
                       (lt, ":distance_to_area", 500),
                       (eq, "$tutorial_enter_mounted", 0),],
       [(tutorial_box,"str_tutorial_enter_mounted", "str_tutorial"), (val_add,"$tutorial_enter_mounted", 1)]),


      (2, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (get_player_agent_no, ":player_agent"),
                       (ge, ":player_agent", 0),
                       (neg|conversation_screen_is_active),
                       (agent_get_position, 1, ":player_agent"),
                       (entry_point_get_position,6,6),
                       (get_distance_between_positions, ":distance_to_area", 1, 6),
                       (lt, ":distance_to_area", 300),
                       (eq, "$tutorial_melee_chest", 0),],
       [(tutorial_box,"str_tutorial_melee_chest", "str_tutorial"), (val_add,"$tutorial_melee_chest", 1)]),
      (2, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (get_player_agent_no, ":player_agent"),
                       (ge, ":player_agent", 0),
                       (agent_get_position, 1, ":player_agent"),
                       (entry_point_get_position,7,7),
                       (get_distance_between_positions, ":distance_to_area", 1, 7),
                       (lt, ":distance_to_area", 300),
                       (eq, "$tutorial_ranged_chest", 0),],
       [(tutorial_box,"str_tutorial_ranged_chest", "str_tutorial"), (val_add,"$tutorial_ranged_chest", 1)]),

      (2, 0, ti_once, [(store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (eq, "$tutorial_item_equipped", 0),
                       (try_begin),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_sword"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_axe"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_spear"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_club"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_battle_axe"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_arrows"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_bolts"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_short_bow"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_crossbow"),
                         (assign, "$tutorial_item_equipped", 1),
                       (else_try),
                         (troop_has_item_equipped, "trp_player", "itm_tutorial_throwing_daggers"),
                         (assign, "$tutorial_item_equipped", 1),
                       (try_end),
                       (eq, "$tutorial_item_equipped", 1),],
       [(tutorial_box,"str_tutorial_item_equipped", "str_tutorial")]),


      

#      (2, 0, ti_once, [(get_player_agent_no, ":player_agent"),
#                       (agent_get_position, 1, ":player_agent"),
#                       (entry_point_get_position,21,21),
#                       (get_distance_between_positions, ":distance_to_area", 1, 21),
#                       (lt, ":distance_to_area", 200),
#                       (eq, "$tutorial_group_of_weapons", 0),],
#       [(tutorial_box,"str_tutorial_group_of_weapons", "str_tutorial"), (val_add,"$tutorial_group_of_weapons", 1)]),

      

      (1, 5, ti_once, [(eq,"$tutorial_camp_stage",0),
                       (neg|conversation_screen_is_active),
                       (eq,"$tutorial_quest_award_taken",0),
                       (store_character_level, ":player_level", "trp_player"),
                       (le, ":player_level", 1),
                       (tutorial_box,"str_tutorial_camp1","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1)]),
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",1),
                       (neg|conversation_screen_is_active),
                       (tutorial_box,"str_tutorial_camp2","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1)]),
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",2),
                       (neg|conversation_screen_is_active),
                       (tutorial_box,"str_tutorial_camp3","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1)]),
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",3),(eq, "$tutorial_award_taken", 0),
                       (neg|conversation_screen_is_active),
                       (tutorial_box,"str_tutorial_camp4","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",2)]),
      
     
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",5),
                       (neg|conversation_screen_is_active),
                       (eq,"$tutorial_quest_taken",1),
                       (tutorial_box,"str_tutorial_camp6","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1)]),

      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",6),
                       (neg|conversation_screen_is_active),
                       (ge,"$num_total_dummies_destroyed",10),
                       (tutorial_box,"str_tutorial_camp7","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1), (assign,"$tutorial_quest_succeeded",1),]),
      
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",7),
                       (neg|conversation_screen_is_active),
                       (eq,"$tutorial_quest_award_taken",1),
                       (tutorial_box,"str_tutorial_camp8","str_tutorial"),
                       (troop_add_proficiency_points, "trp_player", 10),
                       (assign, "$tutorial_last_proficiency_sum", 0),
                       (try_for_range, ":cur_attribute", 0, num_weapon_proficiencies),
                         (store_proficiency_level, ":cur_attribute_point", "trp_player", ":cur_attribute"),
                         (val_add, "$tutorial_last_proficiency_sum", ":cur_attribute_point"),
                       (try_end),],
       [(val_add,"$tutorial_camp_stage",1),]),
      
      (1, 3, ti_once, [(eq,"$tutorial_camp_stage",8),
                       (neg|conversation_screen_is_active),
                       (assign, ":new_proficiency_sum", 0),
                       (try_for_range, ":cur_attribute", 0, num_weapon_proficiencies),
                         (store_proficiency_level, ":cur_attribute_point", "trp_player", ":cur_attribute"),
                         (val_add, ":new_proficiency_sum", ":cur_attribute_point"),
                       (try_end),
                       (assign, reg(48), ":new_proficiency_sum"),
                       (assign, reg(49), "$tutorial_last_proficiency_sum"),
                       (lt,"$tutorial_last_proficiency_sum",":new_proficiency_sum"),
                       (tutorial_box,"str_tutorial_camp9","str_tutorial"),],
          [(val_add,"$tutorial_camp_stage",1)]),

      (2, 0, 0, [(check_quest_active,"qst_destroy_dummies"),
                 (le, "$num_total_dummies_destroyed", 10),],
          [
              (assign, ":progress", "$num_total_dummies_destroyed"),
              (val_mul, ":progress", 10),
              (set_quest_progression,"qst_destroy_dummies",":progress"),
              ]
       ),

    ],
  ),

]
